<div class="sectionY">
	<a href="javascript:history.back()">
		<img src="__PUBLIC__/home/images/a4.png" class="a1" alt="">
	</a>
	<p class="p1">注册</p>
</div>
<div class="kong1"></div>
<div class="login_section2 login_section2x " >
	<form action="">
		<div class="f1 clearfix">
			<img src="__PUBLIC__/home/images/a5.png" class="im1" alt="">
			<input type="text" name="selfphone" class="input1" placeholder="请输入手机号" autocomplete="off">
		</div>
		<div class="f1 clearfix" style="margin-bottom: 0px">
			<img src="__PUBLIC__/home/images/a2.png" alt="">
			<input type="text" autocomplete="off" name="vcode" class="input1" placeholder="请输入验证码">
			<span class="sr_btn" id="getVcode">获取验证码</span>
		</div>
		<div class="f1 clearfix" style="margin-bottom: 0px">
			<img src="__PUBLIC__/home/images/a3.png" alt="">
			<input type="text" name="username" class="input1" placeholder="请输入用户名" maxlength="11"  autocomplete="off">
		</div>
		<div class="f1 clearfix" style="margin-bottom: 0px">
			<img src="__PUBLIC__/home/images/a3.png" alt="">
			<input type="password" name="passwd" class="input1" placeholder="请设置登录密码">
		</div>
		<div class="f1 clearfix" style="margin-bottom: 0px">
			<img src="__PUBLIC__/home/images/a3.png" alt="">
			<input type="password" name="confirm_passwd" class="input1" placeholder="请再次确认登录密码">
		</div>
		<div class="f1 clearfix" style="margin-bottom: 0px">
			<img src="__PUBLIC__/home/images/a3.png" alt="">
			<input type="password" name="sepasswd" class="input1" placeholder="请设置交易密码">
		</div>
		<div class="f1 clearfix" style="margin-bottom: 0px">
			<img src="__PUBLIC__/home/images/a3.png" alt="">
			<input type="password" name="confirm_sepasswd" class="input1" placeholder="请再次确认交易密码">
		</div>
		<div class="f1 clearfix" style="margin-bottom: 0px">
			<img src="__PUBLIC__/home/images/a7.png" alt="">
			<input type="text" name="invite_code" class="input1" placeholder="请填写推荐人" value="{$code}">
		</div>
		<div class="sub">
			<button class="but1" type="button" id="submit">提交注册</button>
		</div>
	</form>
</div>
<script>
    var is_enable=true;
	$(function(){
		$("#getVcode").click(function () {
		    var telephone = $("input[name='selfphone']").val();
		    if(!is_enable){
                return false;
            }
		    if(telephone.trim() == ""){
                layer.msg("手机号不能为空");
                return false;
            }
            var times = 60;
            $.post('{:url("Index/getVcode")}', {telephone:telephone, type:1}, function (res) {
                if(res.result_code == 0){
                    is_enable = false;
                    $("#getVcode").html(times+"秒后发送");
                    var index = setInterval(function () {
                        if(times == 0){
                            clearInterval(index);
                            is_enable = true;
                            $("#getVcode").html("发送验证码");
                        }else{
                            times--;
                            $("#getVcode").html(times+"秒后发送");
                        }
                    }, 1000);
                }else{
                    layer.msg(res.result_info);
                }
            });
		});
		$("#submit").click(function () {
			var data = {};
			data.selfphone = $.trim($("input[name='selfphone']").val());
			data.vcode = $.trim($("input[name='vcode']").val());
			data.username = $.trim($("input[name='username']").val());
			data.passwd = $.trim($("input[name='passwd']").val());
			data.confirm_passwd = $.trim($("input[name='confirm_passwd']").val());
			data.sepasswd = $.trim($("input[name='sepasswd']").val());
			data.invite_code = $.trim($("input[name='invite_code']").val());
			data.confirm_sepasswd = $.trim($("input[name='confirm_sepasswd']").val());
			var re = /^[0-9]+.?[0-9]*$/;
		    
		    //验证用户名不能全部为数字
		    
		    

			if(data.selfphone == ""){
				layer.msg("手机号不能为空");
				return false;
			}
			if(data.vcode == ""){
				layer.msg("验证码不能为空");
				return false;
			}
			
			if(data.username == "" || data.username==undefined){
				layer.msg("用户名不能为空");
				return false;
			}
		    if (re.test(data.username)) {
		        layer.msg("用户名不能为数字开头");
				return false;
		    }


			if(data.passwd == ""){
				layer.msg("密码不能为空");
				return false;
			}
			if(data.sepasswd == ""){
				layer.msg("二级密码不能为空");
				return false;
			}
			// if(data.invite_code == ""){
			// 	layer.msg("请填写推荐人");
			// 	return false;
			// }
			$.post("{:url('Index/register')}", data, function (res) {
				if(res.result_code == 0){

					layer.confirm('注册成功，现在跳转到下载？？',{btn: ['跳转', '不跳转'],shade:0.8,title:"您已注册成功"}, function(){
						var downurl = '{:config("setting.downloadurl")}';
						window.location.href = downurl;
					},function(){
						var downurl = '{:url("Index/login")}';
						window.location.href = downurl;
					});
					return false;
					// setTimeout(function () {
					// 	location.href="{:url('Index/index')}";
					// })
				}else{
					layer.msg(res.result_info);
				}
			});

        });
	})
</script>
